package com.chhlz.module.base.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chhlz.module.base.dao.ConsumptionPatternDao;
import com.chhlz.module.base.model.ConsumptionPattern;
import com.chhlz.module.service.ConsumptionPatternService;

@Service
public class ConsumptionPatternServiceImpl implements ConsumptionPatternService{
	@Autowired
	private ConsumptionPatternDao consumptionPatternDao;

	@Override
	public int save(ConsumptionPattern t) {
		return this.consumptionPatternDao.save(t);
	}

	@Override
	public void update(ConsumptionPattern t) {
		this.consumptionPatternDao.update(t);
	}

	@Override
	public void delete(int id) {
		ConsumptionPattern cp = this.consumptionPatternDao.get(id);
		this.consumptionPatternDao.delete(cp);
	}

	@Override
	public List<ConsumptionPattern> findAll(int page, int rows, String sort, String order) {
		return this.consumptionPatternDao.findAll(page, rows, sort, order);
	}

	@Override
	public boolean isExist(String name) {
		boolean flag = false;
		String hql = "select * from ConsumptionPattern p where p.cpName=" + name;
		if(this.consumptionPatternDao.find(hql).size()>0)
			flag = true;
		return flag;
	}

	@Override
	public int getTotal() {
		return this.consumptionPatternDao.countAll();
	}

}
